package com.catcher.infobackup.xyf;


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.hardware.usb.UsbManager;


/**
 * UsbReceiver
 * 
 * @author Jo 
 */
public class UsbReceiver extends BroadcastReceiver {
    static final String TAG = "UsbReceiver";

    IController.MountCallBack mCallback;
    //Toast mToast;
    public UsbReceiver(IController.MountCallBack callback) {
    	mCallback = callback;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();
        
        /*if(mToast!=null){
            mToast.cancel();
            mToast = null;
        }*/
 
        if(action.equals(UsbManager.ACTION_USB_STATE)){
        	
            boolean connected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
            boolean configuared = intent.getBooleanExtra(UsbManager.USB_CONFIGURED, false);
            
            if(mCallback!=null){
            	mCallback.onUsbStateChanged(connected, configuared);
            }

            /*TextView textView = new TextView(context);
            textView.setBackgroundColor(Color.MAGENTA);
            textView.setTextColor(Color.BLUE);
            textView.setPadding(10, 10, 10, 10);
            textView.setText("USB connected:"+connected+" configuared:"+configuared);
            Toast toastView = new Toast(context);
            toastView.setDuration(Toast.LENGTH_LONG);
            toastView.setGravity(Gravity.CENTER, 0, 0);
            toastView.setView(textView);
            toastView.show();
            mToast = toastView;*/
        }/*else if(action.equals(UsbManager.ACTION_EBEN_USB_STATUS_CHANGED)){
            TextView textView = new TextView(context);
            textView.setBackgroundColor(Color.MAGENTA);
            textView.setTextColor(Color.BLUE);
            textView.setPadding(10, 10, 10, 10);
            textView.setText(intent.toString());
            Toast toastView = new Toast(context);
            toastView.setDuration(Toast.LENGTH_LONG);
            toastView.setGravity(Gravity.CENTER, 0, 0);
            toastView.setView(textView);
            toastView.show();
            mToast = toastView;
        }*/

    }
}
